using HKB.Common;
using HKB.Data.Bll;
using HKB.Data.Model;
using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI.HtmlControls;
namespace HKB.Web.Shop
{
	public class Shop : HoWave_Root
	{
		private GroupBll _bllGroup = null;
		private ShopConfigBll _bll_config = null;
		private DataTable _table_config = null;
		private DataRow _shopconfig = null;
		private OnlineUser _user = null;
		private string actionTabTabInfo = "";
		private string showProType = "";
		public GroupBll BllGroup
		{
			get
			{
				if (this._bllGroup == null)
				{
					this._bllGroup = new GroupBll(this.conn);
				}
				return this._bllGroup;
			}
		}
		public ShopConfigBll bll_config
		{
			get
			{
				ShopConfigBll bll_config;
				if (this._bll_config == null)
				{
					this._bll_config = new ShopConfigBll();
					bll_config = this._bll_config;
				}
				else
				{
					bll_config = this._bll_config;
				}
				return bll_config;
			}
		}
		public DataTable table_config
		{
			get
			{
				DataTable config = this.bll_config.GetConfig();
				if (config.Rows.Count > 0)
				{
					this._table_config = config;
				}
				return this._table_config;
			}
		}
		public DataRow shopconfig
		{
			get
			{
				if (this._shopconfig == null)
				{
					object obj = DataCache.GetCache("shopconfig");
					if (obj == null)
					{
						obj = new ShopConfigBll().GetConfig().Rows[0];
						if (obj != null)
						{
							int configInt = ConfigHelper.GetConfigInt("config");
							DataCache.SetCache("shopconfig", obj, DateTime.Now.AddMinutes((double)configInt), TimeSpan.Zero);
						}
					}
					this._shopconfig = (DataRow)obj;
				}
				return this._shopconfig;
			}
		}
		public OnlineUser user
		{
			get
			{
				OnlineUser user;
				if (this._user == null)
				{
					this._user = new OnlineUser(this.conn);
					this._user.CheckUserLogin();
					user = this._user;
				}
				else
				{
					user = this._user;
				}
				return user;
			}
		}
		public string ActionTabInfo
		{
			get
			{
				if (base.Request.QueryString["Action"] != null)
				{
					this.actionTabTabInfo = base.Request.QueryString["Action"].Trim();
				}
				else
				{
					this.actionTabTabInfo = "";
				}
				return this.actionTabTabInfo;
			}
		}
		public string ShowProType
		{
			get
			{
				if (base.Request.QueryString["showProType"] != null)
				{
					this.showProType = base.Request.QueryString["showProType"].ToString();
				}
				return this.showProType;
			}
		}
		public Shop()
		{
			if (this.config["CloseSite"].ToString() == "1")
			{
				this.WriteErrMsg("", this.config["CloseMessage"].ToString(), "");
			}
		}
		protected override void WriteErrMsg(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/ErrTitle");
			}
			string newValue;
			if (ComeUrl != "")
			{
				newValue = "<a id=\"Button\" href='" + ComeUrl + "'>确定</a>";
			}
			else
			{
				newValue = "<a id=\"Button\" href='javascript:history.go(-1);'>返回</a>";
			}
			string text = Template.GetTemplate(Template.GetTemplatePath("ShopError"));
			text = Template.TransferLabelToHtml(text, false);
			text = text.Replace("{$Title}", errType);
			text = text.Replace("{$Msg}", msg);
			text = text.Replace("{$Button}", newValue);
			text = text.Replace("{$ComeUrl}", ComeUrl);
			HttpContext.Current.Response.Write(text);
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected override void WriteErrMsg2(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/ErrTitle");
			}
			string newValue;
			if (ComeUrl != "")
			{
				newValue = "<a id=\"Button\" href='" + ComeUrl + "'>返回</a>";
			}
			else
			{
				newValue = "<a id=\"Button\" href='javascript:history.back();'>返回</a>";
			}
			string text = Template.GetTemplate(Template.GetTemplatePath("ShopError"));
			text = Template.TransferLabelToHtml(text, false);
			text = text.Replace("{$Title}", errType);
			text = text.Replace("{$Msg}", msg);
			text = text.Replace("{$Button}", newValue);
			text = text.Replace("{$ComeUrl}", ComeUrl);
			HttpContext.Current.Response.Write(text);
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected override void WriteSuccessMsg(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/SuccessTitle");
			}
			string newValue;
			if (ComeUrl != "")
			{
				newValue = "<a id=\"Button\" href='" + ComeUrl + "'>确定</a>";
			}
			else
			{
				newValue = "<a id=\"Button\" href='javascript:history.back();'>返回</a>";
			}
			string text = Template.GetTemplate(Template.GetTemplatePath("ShopSuccess"));
			text = Template.TransferLabelToHtml(text, false);
			text = text.Replace("{$Title}", errType);
			text = text.Replace("{$Msg}", msg);
			text = text.Replace("{$Button}", newValue);
			text = text.Replace("{$ComeUrl}", ComeUrl);
			HttpContext.Current.Response.Write(text);
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected void WriteTemErrMsg(string m_errmsg)
		{
			this.WriteErrMsg("", Language.Get("Common/TemplateErr", m_errmsg), "");
		}
		protected void WriteTemErrMsg(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = "友情提示";
			}
			string newValue;
			if (ComeUrl != "")
			{
				newValue = "<a id=\"Button\" href='" + ComeUrl + "'>确定</a>";
			}
			else
			{
				newValue = "<a id=\"Button\" href='javascript:history.back();'>返回</a>";
			}
			string text = Template.GetTemplate(Template.GetTemplatePath("ShopSuccess"));
			text = Template.TransferLabelToHtml(text, false);
			text = text.Replace("{$Title}", errType);
			text = text.Replace("{$Msg}", msg);
			text = text.Replace("{$Button}", newValue);
			text = text.Replace("{$ComeUrl}", ComeUrl);
			HttpContext.Current.Response.Write(text);
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected void WriteRightErrMsg()
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/RightErr", new string[0]), "");
		}
		protected void WriteCodeErrMsg(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/ErrTitle");
			}
			string newValue;
			if (ComeUrl != "")
			{
				newValue = "<a id=\"Button\" href='" + ComeUrl + "'>返回</a>";
			}
			else
			{
				newValue = "<a id=\"Button\" href='javascript:history.back();'>返回</a>";
			}
			string text = Template.GetTemplate(Template.GetTemplatePath("ShopError"));
			text = Template.TransferLabelToHtml(text, false);
			text = text.Replace("{$Title}", errType);
			text = text.Replace("{$Msg}", msg);
			text = text.Replace("{$Button}", newValue);
			text = text.Replace("{$ComeUrl}", ComeUrl);
			HttpContext.Current.Response.Write(text);
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected void ShowCityArea()
		{
			SiteConfigBll siteConfigBll = new SiteConfigBll();
			if (siteConfigBll.GetSiteString("SiteConfigInfo/CityArea") != "0")
			{
				string text = "";
				if (base.Request.Cookies["Howave_City"] != null)
				{
					text = HttpUtility.UrlDecode(base.Request.Cookies["Howave_City"].Values["_Name"]);
				}
				HtmlInputButton htmlInputButton = (HtmlInputButton)this.Page.FindControl("Input_City");
				if (text != "")
				{
					htmlInputButton.Value = " " + text + " ";
				}
				else
				{
					htmlInputButton.Value = " 全国 ";
				}
			}
			else
			{
				if (this.Page.FindControl("DivCity") != null)
				{
					this.Page.FindControl("DivCity").Visible = false;
				}
			}
		}
		private string TimeString(DateTime dt)
		{
			Random random = new Random();
			return dt.ToString("yyyyMMddHHmmssfff") + random.Next(100, 999);
		}
		protected void ClientRelation(int dianpuID, string type)
		{
			if (this.user.UserID > 0)
			{
				string sql = "select GroupPower,ShopOwnerID from HL_User,HL_Group,HLShop_Shop where HL_User.GroupID=HL_Group.GroupID and HL_User.UserID=ShopOwnerID and HLShop_Shop.ShopID=" + dianpuID;
				DataTable dataTable = this.conn.GetDataTable(sql);
				bool flag = false;
				int num = 0;
				if (dataTable != null && dataTable.Rows.Count > 0)
				{
					string text = "";
					if (dataTable.Rows[0]["GroupPower"] != DBNull.Value)
					{
						text = dataTable.Rows[0]["GroupPower"].ToString();
					}
					if (dataTable.Rows[0]["ShopOwnerID"] != DBNull.Value)
					{
						num = Convert.ToInt32(dataTable.Rows[0]["ShopOwnerID"].ToString());
					}
					if (num > 0 && num != this.user.UserID)
					{
						if (!string.IsNullOrEmpty(text))
						{
							string[] array = text.Split(new char[]
							{
								','
							});
							for (int i = 0; i < array.Length; i++)
							{
								if (array[i] == "useclientrelation")
								{
									flag = true;
									break;
								}
							}
						}
					}
				}
				if (flag)
				{
					string sql2 = "select *,HL_User.Sex  from HL_User,HL_UserInfo where HL_User.UserID=HL_UserInfo.UserID and HL_User.UserID=" + this.user.UserID;
					DataTable dataTable2 = this.conn.GetDataTable(sql2);
					if (dataTable2 != null && dataTable2.Rows.Count > 0)
					{
						DataRow dataRow = dataTable2.Rows[0];
						string text2 = dataRow["UserName"].ToString();
						string text3 = dataRow["TrueName"].ToString();
						HKB.Data.Model.Client clientByClientName = HKB.Data.Bll.Client.instance.GetClientByClientName(text2, num);
						if (clientByClientName != null)
						{
							int clientID = clientByClientName.ClientID;
							bool flag2 = this.UpdateClientInfoModel(clientByClientName, text3, type);
							if (flag2)
							{
								HKB.Data.Model.ClientContacter contacterByClientId = HKB.Data.Bll.ClientContacter.instance.GetContacterByClientId(clientID, num);
								if (contacterByClientId != null)
								{
									HKB.Data.Model.ClientContacter clientContacter = this.ClientContacterByUserInfo(dataRow, text2, text3, num);
									clientContacter.UpdateTime = new DateTime?(DateTime.Now);
									clientContacter.ClientID = new int?(clientID);
									clientContacter.ContacterID = contacterByClientId.ContacterID;
									bool flag3 = HKB.Data.Bll.ClientContacter.instance.Update(clientContacter);
								}
								else
								{
									this.AddContacter(dataRow, text2, text3, num, clientID);
								}
							}
						}
						else
						{
							HKB.Data.Model.Client clientInfoModel = this.GetClientInfoModel(text2, text3, num, type);
							int kehuID = HKB.Data.Bll.Client.instance.Add(clientInfoModel);
							this.AddContacter(dataRow, text2, text3, num, kehuID);
						}
					}
				}
			}
		}
		private int AddContacter(DataRow drUser, string UserName, string TrueName, int SalerID, int kehuID)
		{
			int result = 0;
			if (kehuID > 0)
			{
				HKB.Data.Model.ClientContacter clientContacter = this.Contacter(drUser, UserName, TrueName, SalerID);
				clientContacter.ClientID = new int?(kehuID);
				result = HKB.Data.Bll.ClientContacter.instance.Add(clientContacter);
			}
			return result;
		}
		private HKB.Data.Model.ClientContacter Contacter(DataRow drUser, string UserName, string TrueName, int SalerID)
		{
			HKB.Data.Model.ClientContacter clientContacter = this.ClientContacterByUserInfo(drUser, UserName, TrueName, SalerID);
			clientContacter.UserType = "";
			clientContacter.InterestsOfLife = "";
			clientContacter.InterestsOfCulture = "";
			clientContacter.InterestsOfAmusement = "";
			clientContacter.InterestsOfSport = "";
			clientContacter.Company = "";
			clientContacter.Department = "";
			clientContacter.Position = "";
			clientContacter.Operation = "";
			clientContacter.CompanyAddress = "";
			clientContacter.OfficePhone = "";
			clientContacter.CreateTime = new DateTime?(DateTime.Now);
			clientContacter.UpdateTime = new DateTime?(DateTime.Now);
			clientContacter.Yahoo = "";
			clientContacter.UC = "";
			return clientContacter;
		}
		private HKB.Data.Model.ClientContacter ClientContacterByUserInfo(DataRow drUser, string UserName, string TrueName, int SalerID)
		{
			HKB.Data.Model.ClientContacter clientContacter = new HKB.Data.Model.ClientContacter();
			clientContacter.Owner = SalerID;
			clientContacter.UserName = UserName;
			clientContacter.TrueName = TrueName;
			string country = "";
			if (drUser["Country"] != DBNull.Value)
			{
				country = drUser["Country"].ToString();
			}
			clientContacter.Country = country;
			string province = "";
			if (drUser["Province"] != DBNull.Value)
			{
				province = drUser["Province"].ToString();
			}
			clientContacter.Province = province;
			string city = "";
			if (drUser["City"] != DBNull.Value)
			{
				city = drUser["City"].ToString();
			}
			clientContacter.City = city;
			string districts = "";
			if (drUser["CMArea"] != DBNull.Value)
			{
				districts = drUser["CMArea"].ToString();
			}
			clientContacter.Districts = districts;
			string address = "";
			if (drUser["Address"] != DBNull.Value)
			{
				address = drUser["Address"].ToString();
			}
			clientContacter.Address = address;
			string zipCode = "";
			if (drUser["ZipCode"] != DBNull.Value)
			{
				zipCode = drUser["ZipCode"].ToString();
			}
			clientContacter.ZipCode = zipCode;
			string homePhone = "";
			if (drUser["HomePhone"] != DBNull.Value)
			{
				homePhone = drUser["HomePhone"].ToString();
			}
			clientContacter.HomePhone = homePhone;
			string mobile = "";
			if (drUser["MobilePhone"] != DBNull.Value)
			{
				mobile = drUser["MobilePhone"].ToString();
			}
			clientContacter.Mobile = mobile;
			string fax = "";
			if (drUser["Fax"] != DBNull.Value)
			{
				fax = drUser["Fax"].ToString();
			}
			clientContacter.Fax = fax;
			string email = "";
			if (drUser["Email"] != DBNull.Value)
			{
				email = drUser["Email"].ToString();
			}
			clientContacter.Email = email;
			string homepage = "";
			if (drUser["HomePage"] != DBNull.Value)
			{
				homepage = drUser["HomePage"].ToString();
			}
			clientContacter.Homepage = homepage;
			string qQ = "";
			if (drUser["OICQ"] != DBNull.Value)
			{
				qQ = drUser["OICQ"].ToString();
			}
			clientContacter.QQ = qQ;
			string mSN = "";
			if (drUser["MSN"] != DBNull.Value)
			{
				mSN = drUser["MSN"].ToString();
			}
			clientContacter.MSN = mSN;
			string title = "";
			if (drUser["NickName"] != DBNull.Value)
			{
				title = drUser["NickName"].ToString();
			}
			clientContacter.Title = title;
			clientContacter.Sex = 2;
			if (drUser["Sex"] != DBNull.Value)
			{
				clientContacter.Sex = Convert.ToInt32(drUser["Sex"].ToString());
			}
			clientContacter.NativePlace = drUser["ComeFrom"].ToString();
			clientContacter.Nation = drUser["Nation"].ToString();
			if (!string.IsNullOrEmpty(drUser["Birthday"].ToString()))
			{
				clientContacter.Birthday = new DateTime?(DateTime.Parse(drUser["Birthday"].ToString()));
			}
			string iDCard = "";
			if (drUser["IDCard"] != DBNull.Value)
			{
				iDCard = drUser["IDCard"].ToString();
			}
			clientContacter.IDCard = iDCard;
			clientContacter.Marriage = 3;
			if (drUser["Marriage"] != DBNull.Value)
			{
				clientContacter.Marriage = Convert.ToInt32(drUser["Marriage"].ToString());
			}
			string family = "";
			if (drUser["Family"] != DBNull.Value)
			{
				family = drUser["Family"].ToString();
			}
			clientContacter.Family = family;
			string income = "";
			if (drUser["InCome"] != DBNull.Value)
			{
				income = drUser["InCome"].ToString();
			}
			clientContacter.Income = income;
			string education = "";
			if (drUser["Eductation"] != DBNull.Value)
			{
				education = drUser["Eductation"].ToString();
			}
			clientContacter.Education = education;
			string graduateFrom = "";
			if (drUser["GraduteSchool"] != DBNull.Value)
			{
				graduateFrom = drUser["GraduteSchool"].ToString();
			}
			clientContacter.GraduateFrom = graduateFrom;
			string interestsOfOther = "";
			if (drUser["Interests"] != DBNull.Value)
			{
				interestsOfOther = drUser["Interests"].ToString();
			}
			clientContacter.InterestsOfOther = interestsOfOther;
			return clientContacter;
		}
		public HKB.Data.Model.Client GetClientInfoModel(string ClientName, string ShortedForm, int SalerID, string type)
		{
			HKB.Data.Model.Client client = new HKB.Data.Model.Client();
			client.ClientName = ClientName;
			client.ShortedForm = ShortedForm;
			client.ParentID = new int?(0);
			client.ClientNum = this.TimeString(DateTime.Now);
			client.ClientType = "ClientType_gr";
			client.Area = "";
			client.ClientField = "";
			client.ValueLevel = "";
			client.CreditLevel = "";
			client.Importance = "";
			client.ConnectionLevel = "";
			client.SourceType = "SourceType_hlw";
			if (type != null)
			{
				if (!(type == "browse"))
				{
					if (!(type == "buyorder"))
					{
						if (type == "outlinebuy")
						{
							client.GroupID = "GroupID_gm";
							client.PeriodType = "PeriodType_shfw";
							client.IsBusiness = "IsBusiness_2";
						}
					}
					else
					{
						client.GroupID = "GroupID_gm";
						client.PeriodType = "PeriodType_shfw";
						client.IsBusiness = "IsBusiness_0";
					}
				}
				else
				{
					client.GroupID = "GroupID_qz";
					client.PeriodType = "PeriodType_sqfw";
					client.IsBusiness = "IsBusiness_0";
				}
			}
			client.Remark = "";
			client.VisitTimes = new int?(0);
			client.LastVisitTime = null;
			client.CreateTime = new DateTime?(DateTime.Now);
			client.UpdateTime = new DateTime?(DateTime.Now);
			client.LastRelationTime = new DateTime?(DateTime.Now);
			client.Owner = new int?(SalerID);
			return client;
		}
		public bool UpdateClientInfoModel(HKB.Data.Model.Client getObj, string ShortedForm, string type)
		{
			bool result = false;
			if (getObj != null)
			{
				HKB.Data.Model.Client client = new HKB.Data.Model.Client();
				client.ClientID = getObj.ClientID;
				client.UpdateTime = new DateTime?(DateTime.Now);
				client.ShortedForm = ShortedForm;
				if (type != null)
				{
					if (!(type == "browse"))
					{
						if (!(type == "buyorder"))
						{
							if (!(type == "outlinebuy"))
							{
							}
						}
						else
						{
							if (getObj.GroupID.Trim() == "GroupID_qz")
							{
								client.GroupID = "GroupID_gm";
							}
							if (getObj.PeriodType.Trim() == "PeriodType_sqfw")
							{
								client.PeriodType = "PeriodType_shfw";
							}
						}
					}
				}
				result = HKB.Data.Bll.Client.instance.Update(client);
			}
			return result;
		}
		public bool OwnerStockPower(int salerID)
		{
			return this.BllGroup.OwnerPower(salerID, "stockmanage");
		}
		public bool OwnerPromotionPower(int salerID)
		{
			return this.BllGroup.OwnerPower(salerID, "promotionmanage");
		}
		public int UserGetCouponMethod(int orderID, string buyername, string type, decimal orderMoney, string couponInfoIDStr)
		{
			int result = 0;
			if (!string.IsNullOrEmpty(couponInfoIDStr))
			{
				string sql = "select NeedsMoney,item.* from HL_CouponInfo as info,HL_CouponItem as item where info.CouponInfoID=item.CouponInfoID and(DATEDIFF(DD,info.EndDate,GETDATE())<=0) and info.CouponInfoID in (" + couponInfoIDStr + ") order by item.CouponInfoID";
				DataTable dataTable = this.conn.GetDataTable(sql);
				if (type == "get")
				{
					for (int i = 0; i < dataTable.Rows.Count; i++)
					{
						decimal d = Convert.ToDecimal(dataTable.Rows[i]["NeedsMoney"].ToString());
						if (orderMoney >= d)
						{
							if (dataTable.Rows[i]["UserName"] == DBNull.Value)
							{
								HKB.Data.Bll.CouponItem couponItem = new HKB.Data.Bll.CouponItem();
								int num = Convert.ToInt32(dataTable.Rows[i]["CouponItemID"].ToString());
								HKB.Data.Model.CouponItem model = couponItem.GetModel(num);
								model.CouponItemID = num;
								model.UserName = buyername;
								model.GainDate = new DateTime?(DateTime.Now);
								model.GainOrderID = new int?(orderID);
								bool flag = couponItem.Update(model);
								if (flag)
								{
									result = num;
									break;
								}
							}
						}
					}
				}
			}
			return result;
		}
		public DataTable UserUseCouponMethod(string buyername, int shangpinID, string type, string myself, string groupid)
		{
			DataTable result = null;
			if (type == "use")
			{
				string text = "select CouponParvalue,NeedsMoney,item.* from HL_CouponInfo as info,HL_CouponItem as item where info.CouponInfoID=item.CouponInfoID and(DATEDIFF(DD,info.EndDate,GETDATE())<=0)  and UseStatus=0 and UserName='" + buyername + "' ";
				if (myself == "limit")
				{
					string text2 = this.UserGetCouponInfoIDStr(shangpinID, type, groupid);
					if (!string.IsNullOrEmpty(text2))
					{
						text = text + " and info.CouponInfoID in (" + text2 + ") ";
					}
				}
				text += " order by item.CouponInfoID";
				result = this.conn.GetDataTable(text);
			}
			return result;
		}
		public string UserGetCouponInfoIDStr(int shangpinID, string type, string groupid)
		{
			string text = "";
			HKB.Data.Bll.CouponInfo couponInfo = new HKB.Data.Bll.CouponInfo();
			DataTable dataTable = couponInfo.GetAllList().Tables[0];
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				string couponInfoID = dataTable.Rows[i]["CouponInfoID"].ToString();
				string userGroupID = dataTable.Rows[i]["UserGroupID"].ToString();
				string text2 = this.getCouponIDStrByUserGroup(couponInfoID, userGroupID, groupid);
				if (!string.IsNullOrEmpty(text2))
				{
					text = text + text2 + ",";
				}
			}
			text = this.AgainOrder(text);
			if (!string.IsNullOrEmpty(text))
			{
				DataTable dataTable2 = couponInfo.GetList("CouponInfoID in (" + text + ")").Tables[0];
				text = "";
				string text2 = "";
				for (int i = 0; i < dataTable2.Rows.Count; i++)
				{
					string couponInfoID = dataTable2.Rows[i]["CouponInfoID"].ToString();
					string text3 = dataTable2.Rows[i]["GetFashion"].ToString();
					string text4 = dataTable2.Rows[i]["GetFashionContent"].ToString();
					string text5 = dataTable.Rows[i]["UseProductType"].ToString();
					string text6 = dataTable.Rows[i]["UseProductIDs"].ToString();
					if (type == "get")
					{
						if (!string.IsNullOrEmpty(text3))
						{
							string text7 = text3;
							if (text7 != null)
							{
								if (!(text7 == "BuyAny"))
								{
									if (!(text7 == "BuyClassify"))
									{
										if (!(text7 == "BuySpecific"))
										{
											if (!(text7 == "BuyOrderMoney"))
											{
											}
										}
										else
										{
											string sqlPro = "select SalerID,ProductID from HLShop_Product where ProductID in (" + text4 + ")";
											text2 = this.getCouponIDStrByProductID(text4, sqlPro, couponInfoID, shangpinID.ToString());
										}
									}
								}
							}
						}
					}
					else
					{
						if (type == "use")
						{
							if (!string.IsNullOrEmpty(text5))
							{
								string text7 = text5;
								if (text7 != null)
								{
									if (!(text7 == "LimitAll"))
									{
										if (!(text7 == "LimitClassify"))
										{
											if (text7 == "LimitSpecific")
											{
												string sqlPro = "select SalerID,ProductID from HLShop_Product where ProductID in (" + text6 + ")";
												text2 = this.getCouponIDStrByProductID(text6, sqlPro, couponInfoID, shangpinID.ToString());
											}
										}
									}
								}
							}
						}
					}
					if (!string.IsNullOrEmpty(text2))
					{
						text = text + text2 + ",";
					}
				}
				text = this.AgainOrder(text);
			}
			return text;
		}
		public string SalerGetCouponInfoIDStr(string salerId)
		{
			string text = "";
			HKB.Data.Bll.CouponInfo couponInfo = new HKB.Data.Bll.CouponInfo();
			string text2 = "";
			DataTable dataTable = couponInfo.GetAllList().Tables[0];
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				string couponInfoID = dataTable.Rows[i]["CouponInfoID"].ToString();
				string text3 = dataTable.Rows[i]["GetFashion"].ToString();
				string text4 = dataTable.Rows[i]["GetFashionContent"].ToString();
				if (!string.IsNullOrEmpty(text3))
				{
					string text5 = text3;
					if (text5 != null)
					{
						if (!(text5 == "BuyAny"))
						{
							if (!(text5 == "BuyClassify"))
							{
								if (!(text5 == "BuySpecific"))
								{
									if (!(text5 == "BuyOrderMoney"))
									{
									}
								}
								else
								{
									string sqlPro = "select SalerID,ProductID from HLShop_Product where ProductID in (" + text4 + ")";
									text2 = this.getCouponIDStrBySalerID(text4, sqlPro, couponInfoID, salerId);
								}
							}
						}
					}
				}
				if (!string.IsNullOrEmpty(text2))
				{
					text = text + text2 + ",";
				}
			}
			return this.AgainOrder(text);
		}
		private string AgainOrder(string couponinfoidstr)
		{
			if (!string.IsNullOrEmpty(couponinfoidstr))
			{
				couponinfoidstr = couponinfoidstr.Substring(0, couponinfoidstr.Length - 1);
				if (couponinfoidstr.Contains(","))
				{
					string[] array = couponinfoidstr.Split(new char[]
					{
						','
					});
					ArrayList arrayList = new ArrayList();
					for (int i = 0; i < array.Length; i++)
					{
						if (!arrayList.Contains(array[i]))
						{
							arrayList.Add(array[i]);
						}
					}
					couponinfoidstr = string.Join(",", (string[])arrayList.ToArray(typeof(string)));
				}
			}
			return couponinfoidstr;
		}
		private string getCouponIDStrByUserGroup(string couponInfoID, string userGroupID, string groupid)
		{
			string result = "";
			bool flag = false;
			if (!string.IsNullOrEmpty(userGroupID))
			{
				if (userGroupID.Contains(","))
				{
					string[] array = userGroupID.Split(new char[]
					{
						','
					});
					for (int i = 0; i < array.Length; i++)
					{
						if (groupid == array[i])
						{
							flag = true;
							break;
						}
					}
				}
				else
				{
					if (groupid == userGroupID)
					{
						flag = true;
					}
				}
				if (flag)
				{
					result = couponInfoID;
				}
			}
			return result;
		}
		private string getCouponIDStrByProductID(string getFashionContent, string sqlPro, string couponInfoID, string productID)
		{
			string result = "";
			bool flag = false;
			if (!string.IsNullOrEmpty(getFashionContent))
			{
				DataTable dataTable = this.conn.GetDataTable(sqlPro);
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					string a = dataTable.Rows[i]["ProductID"].ToString();
					if (a == productID)
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					result = couponInfoID;
				}
			}
			return result;
		}
		private string getCouponIDStrBySalerID(string getContent, string sqlPro, string couponInfoID, string salerID)
		{
			string text = "";
			if (!string.IsNullOrEmpty(getContent))
			{
				DataTable dataTable = this.conn.GetDataTable(sqlPro);
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					string a = dataTable.Rows[i]["SalerID"].ToString();
					if (a == salerID)
					{
						text = text + couponInfoID + ",";
					}
				}
				if (text != "")
				{
					text = text.Substring(0, text.Length - 1);
				}
			}
			return text;
		}
		public bool OwnerPowerFinancemanage(int salerID)
		{
			return this.BllGroup.OwnerPower(salerID, "financemanage");
		}
		public bool OwnerPowerClientRelation(int salerID)
		{
			return this.BllGroup.OwnerPower(salerID, "useclientrelation");
		}
		public bool OwnerPowerShowMyCoupon(int loginUserID)
		{
			return this.BllGroup.OwnerPower(loginUserID, "showmycoupon");
		}
		public void AddInfoItem(int orderFormId, string deliverStatus, int salerID)
		{
			if (orderFormId > 0)
			{
				Shop_Order shop_Order = new Shop_Order();
				DataTable orderByOrderID = shop_Order.GetOrderByOrderID(orderFormId);
				for (int i = 0; i < orderByOrderID.Rows.Count; i++)
				{
					string infoNumber = "XSCKD" + DateTime.Now.TimeString();
					DateTime receiptEndDate = DateTime.Now.AddMonths(1);
					string receiptDate = "";
					string inputer = orderByOrderID.Rows[i]["SalerName"].ToString();
					int num = Convert.ToInt32(orderByOrderID.Rows[i]["SalerID"].ToString());
					string text = "JZPZ" + DateTime.Now.TimeString();
					decimal num2 = 0m;
					if (orderByOrderID.Rows[i]["MoneyTotal"] != DBNull.Value)
					{
						num2 = Convert.ToDecimal(orderByOrderID.Rows[i]["MoneyTotal"].ToString());
					}
					if (orderByOrderID.Rows[i]["MoneyGoods"] != DBNull.Value)
					{
						decimal num3 = Convert.ToDecimal(orderByOrderID.Rows[i]["MoneyGoods"].ToString());
					}
					if (orderByOrderID.Rows[i]["Deliver_TotalPrice"] != DBNull.Value)
					{
						decimal num4 = Convert.ToDecimal(orderByOrderID.Rows[i]["Deliver_TotalPrice"].ToString());
					}
					if (orderByOrderID.Rows[i]["Invoice_TotalPrice"] != DBNull.Value)
					{
						decimal num5 = Convert.ToDecimal(orderByOrderID.Rows[i]["Invoice_TotalPrice"].ToString());
					}
					decimal alreadMoney = 0m;
					decimal fee = 0m;
					decimal receiptMoney = num2;
					int num6 = this.StockInfoOrderAdd(orderFormId, infoNumber, receiptMoney, alreadMoney, fee, receiptEndDate, receiptDate, inputer, this.user.UserID, deliverStatus);
					if (num6 > 0)
					{
						this.StockOrderItemAdd(orderFormId, num6, infoNumber);
					}
				}
			}
		}
		private int StockInfoOrderAdd(int orderid, string infoNumber, decimal ReceiptMoney, decimal alreadMoney, decimal fee, DateTime ReceiptEndDate, string ReceiptDate, string inputer, int ownerID, string deliverStatus)
		{
			HKB.Data.Model.StockInfoOrder stockInfoOrder = new HKB.Data.Model.StockInfoOrder();
			stockInfoOrder.InfoNumber = infoNumber;
			stockInfoOrder.OrderID = new int?(orderid);
			stockInfoOrder.StockOrderType = "outSell";
			stockInfoOrder.StockStatus = new int?(2);
			if (!string.IsNullOrEmpty(deliverStatus))
			{
				if (deliverStatus == "1" || deliverStatus == "2")
				{
					stockInfoOrder.StockStatus = new int?(3);
					stockInfoOrder.StockDate = new DateTime?(DateTime.Now);
				}
			}
			stockInfoOrder.Fee = new decimal?(fee);
			stockInfoOrder.ReceiptMoney = new decimal?(ReceiptMoney);
			stockInfoOrder.AlreadyReceiptMoney = new decimal?(alreadMoney);
			stockInfoOrder.ReceiptEndDate = new DateTime?(ReceiptEndDate);
			if (!string.IsNullOrEmpty(ReceiptDate))
			{
				stockInfoOrder.ReceiptDate = new DateTime?(Convert.ToDateTime(ReceiptDate));
			}
			stockInfoOrder.CreateDate = new DateTime?(DateTime.Now);
			stockInfoOrder.Inputer = inputer;
			stockInfoOrder.Remark = "";
			stockInfoOrder.OwnerID = ownerID;
			return BLLInstance.BllStockInfoOrder.Add(stockInfoOrder);
		}
		private int StockOrderItemAdd(int orderid, int stockOrderID, string infoNumber)
		{
			int num = 0;
			Shop_OrderItem shop_OrderItem = new Shop_OrderItem();
			DataTable partItemByOrderID = shop_OrderItem.GetPartItemByOrderID(orderid);
			for (int i = 0; i < partItemByOrderID.Rows.Count; i++)
			{
				int value = Convert.ToInt32(partItemByOrderID.Rows[i]["ProductID"].ToString());
				int value2 = Convert.ToInt32(partItemByOrderID.Rows[i]["Quantity"].ToString());
				decimal value3 = 0m;
				if (partItemByOrderID.Rows[i]["Price"] != DBNull.Value)
				{
					value3 = Convert.ToDecimal(partItemByOrderID.Rows[i]["Price"].ToString());
				}
				string unit = partItemByOrderID.Rows[i]["PUnit"].ToString();
				HKB.Data.Model.StockItemOrder stockItemOrder = new HKB.Data.Model.StockItemOrder();
				stockItemOrder.InfoOrderID = new int?(stockOrderID);
				stockItemOrder.InfoNumber = infoNumber;
				stockItemOrder.ProductID = new int?(value);
				stockItemOrder.StockCount = new int?(value2);
				stockItemOrder.Price = new decimal?(value3);
				stockItemOrder.Unit = unit;
				num += BLLInstance.BllStockItemOrder.Add(stockItemOrder);
			}
			return num;
		}
		private int AccountAoucherAdd(int stockOrderID, string infoNumber, string AccountANumber, int accountACount, string inputer, int ownerID)
		{
			HKB.Data.Model.AccountAoucher accountAoucher = new HKB.Data.Model.AccountAoucher();
			accountAoucher.StockOrderID = new int?(stockOrderID);
			accountAoucher.AccountANumber = AccountANumber;
			accountAoucher.AccountACount = new int?(accountACount);
			accountAoucher.AccountAExplain = "编号" + infoNumber + "的出库单记账凭证";
			accountAoucher.Inputer = inputer;
			accountAoucher.IsCaudit = false;
			accountAoucher.IsAccount = false;
			accountAoucher.IsCashier = false;
			accountAoucher.InputDate = new DateTime?(DateTime.Now);
			accountAoucher.OwnerID = ownerID;
			return BLLInstance.BllAccountAoucher.Add(accountAoucher);
		}
		public bool ShowstandpriceProduct()
		{
			bool result = false;
			if (this.table_config.Columns.Contains("Showstandprice"))
			{
				if (this.table_config.Rows[0]["Showstandprice"] != DBNull.Value)
				{
					if (this.table_config.Rows[0]["Showstandprice"].ToString().Trim() == "1")
					{
						result = true;
					}
				}
			}
			return result;
		}
		public bool ShowActionProduct()
		{
			bool result = false;
			if (this.table_config.Columns.Contains("ShowAction"))
			{
				if (this.table_config.Rows[0]["ShowAction"] != DBNull.Value)
				{
					if (this.table_config.Rows[0]["ShowAction"].ToString().Trim() == "1")
					{
						result = true;
					}
				}
			}
			return result;
		}
		public bool ShowTeamProduct()
		{
			bool result = false;
			if (this.table_config.Columns.Contains("ShowTeam"))
			{
				if (this.table_config.Rows[0]["ShowTeam"] != DBNull.Value)
				{
					if (this.table_config.Rows[0]["ShowTeam"].ToString().Trim() == "1")
					{
						result = true;
					}
				}
			}
			return result;
		}
		public bool ShowPromoteProduct()
		{
			bool result = false;
			if (this.table_config.Columns.Contains("ShowPromote"))
			{
				if (this.table_config.Rows[0]["ShowPromote"] != DBNull.Value)
				{
					if (this.table_config.Rows[0]["ShowPromote"].ToString().Trim() == "1")
					{
						result = true;
					}
				}
			}
			return result;
		}
		public bool ShowScoreProduct()
		{
			bool result = false;
			if (this.table_config.Columns.Contains("ShowScore"))
			{
				if (this.table_config.Rows[0]["ShowScore"] != DBNull.Value)
				{
					if (this.table_config.Rows[0]["ShowScore"].ToString().Trim() == "1")
					{
						result = true;
					}
				}
			}
			return result;
		}
	}
}
